﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using SqlCon;
namespace yfxt
{
    public partial class xxwh_ypxx_xg : Form
    {
        public xxwh_ypxx_xg()
        {
            InitializeComponent();
        }
        xxwh_ypxx ypxx;

        SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction);
        private void xxwh_ypxx_xg_Load(object sender, EventArgs e)
        {
            ypxx = (xxwh_ypxx)this.Owner;

            string s_select = "select @ypmc=ypmc,@ypgg=ypgg,@ypdw=ypdw,@gcsl=gcsl,@dcsl=dcsl,@zfpb=zfpb,@pydm=pydm from yk_typk where ypxh=" + ypxx.s_temp.ToString() + " ";

            if (conn.State != ConnectionState.Open) { conn.Open(); }

            SqlParameter sp_01, sp_02, sp_03, sp_04, sp_05, sp_06, sp_07;
            using (SqlCommand cmd = new SqlCommand(s_select, conn))
            {
                sp_01 = cmd.Parameters.Add("@ypmc", SqlDbType.NVarChar, 40);
                sp_02 = cmd.Parameters.Add("@ypgg", SqlDbType.NVarChar, 40);
                sp_03 = cmd.Parameters.Add("@ypdw", SqlDbType.NVarChar, 20);
                sp_04 = cmd.Parameters.Add("@gcsl", SqlDbType.Decimal, 20);
                sp_05 = cmd.Parameters.Add("@dcsl", SqlDbType.Decimal, 20);
                sp_06 = cmd.Parameters.Add("@zfpb", SqlDbType.NVarChar, 10);
                sp_07 = cmd.Parameters.Add("@pydm", SqlDbType.NVarChar, 40);

                sp_01.Direction = ParameterDirection.Output;
                sp_02.Direction = ParameterDirection.Output;
                sp_03.Direction = ParameterDirection.Output;
                sp_04.Direction = ParameterDirection.Output;
                sp_05.Direction = ParameterDirection.Output;
                sp_06.Direction = ParameterDirection.Output;
                sp_07.Direction = ParameterDirection.Output;

                cmd.ExecuteNonQuery();


                textBox1.Text = sp_01.Value.ToString();
                textBox2.Text = sp_02.Value.ToString();
                textBox3.Text = sp_03.Value.ToString();
                textBox4.Text = sp_04.Value.ToString();
                textBox5.Text = sp_05.Value.ToString();
                textBox6.Text = sp_07.Value.ToString();




                if (sp_06.Value.ToString().Equals("0"))
                {
                    checkBox1.Checked = false;
                }
                else { checkBox1.Checked = true; }

            }



            //MessageBox.Show(ypxx.s_temp.ToString());
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string zfpb;

            if (checkBox1.Checked == true) { zfpb = "1"; }
            else { zfpb = "0"; }
            string s_update = "update yk_typk set ypmc='" + textBox1.Text.ToString() + "' ,ypgg='" + textBox2.Text.ToString() +
                               "', ypdw='" + textBox3.Text.ToString() + "' ,gcsl=" + textBox4.Text.ToString() + " ,dcsl=" + textBox5.Text.ToString() +
                               ", zfpb=" + zfpb + ",pydm='" + textBox6.Text.ToString() + "' where ypxh=" + ypxx.s_temp.ToString() + " ";


            if (conn.State != ConnectionState.Open) { conn.Open(); }

            using (SqlCommand cmd = new SqlCommand(s_update, conn))
            {
                if (MessageBox.Show("您是否确定修改" + textBox1.Text.ToString() + "药？？", "温馨的提示", MessageBoxButtons.YesNoCancel) == DialogResult.Yes)
                {
                    cmd.ExecuteNonQuery();
                }
                MessageBox.Show("修改成功！！");
            }



        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
